import { Subject } from 'rxjs';
import type { Observer } from 'rxjs';
import type { CmdOptions } from './types';

export default class CommandService {
  subject: Subject<CmdOptions>;

  constructor() {
    this.subject = new Subject<CmdOptions>();
  }

  runCommand(options: CmdOptions) {
    this.subject.next(options);
  }

  subscribe(
    obsever: Partial<Observer<CmdOptions>> | ((value: CmdOptions) => void)
  ) {
    return this.subject.subscribe(obsever);
  }
}
